// 首页限时秒杀和频道广场  逻辑

import '../sass/_buybuybuy.scss'

const miaosha_goods = document.querySelector('.miaosha_goods')
const square_goods = document.querySelector('.square_goods')

async function miaoshaList() {

   const res = await $.ajax({
        url:'http://localhost:8888/goods/list',
        data: {
            current: 1,
            pagesize: 12,
            search: '',
            filter:'',
            saleType:'5',
            sortType:'id',
            sortMethod:'ASC',
            category:''
        },
       
    })
let str =``
res.list.forEach( item => {
  str+= `
  <li data-id='${item.goods_id}'>

  <img width=270 height=300 data-src="${item.img_big_logo}" alt="" class="goods_img"> 
  <p class="jieshao">
  ${item.title}
  </p>
  <p class="price">
        <span class="new">￥${item.current_price}</span>
        <span class="old">￥${item.price}</span>
  </p>
</li>
  `
})

miaosha_goods.innerHTML = str
useLazy()
}
miaoshaList()

async function squareList() {

    const res1 = await $.ajax({
         url:'http://localhost:8888/goods/list',
         data: {
             current: 1,
             pagesize: 12,
             search: '',
             filter:'',
             saleType:'8',
             sortType:'id',
             sortMethod:'ASC',
             category:''
         },
        
     })
    //  console.log(res1)
 let str =``
 res1.list.forEach( item => {
   str+= `
   <li data-id='${item.goods_id}'>
 
   <img width=270 height=300 data-src="${item.img_big_logo}" alt="" class="goods_img"> 
   <p class="jieshao">
   ${item.title}
   </p>
   <p class="price">
         <span class="new">￥${item.current_price}</span>
         <span class="old">￥${item.price}</span>
   </p>
 </li>
   `
 })
 
 square_goods.innerHTML = str
 useLazy1()
 }
squareList()
function useLazy(){
  var images = document.querySelectorAll('.miaosha_goods > li > img')
  new LazyLoad( images )
}
function useLazy1(){
  var images1 = document.querySelectorAll('.square_goods > li > img')
  new LazyLoad( images1 )
}


/************* +++跳转详情页 ************/
miaosha_goods.addEventListener('click', e => {
  if (e.target.nodeName === 'LI') {

      const id = e.target.dataset.id
      window.sessionStorage.setItem('goodsId', id)
      window.location.href = 'detail.html'

  }
})

square_goods.addEventListener('click', e => {
  if (e.target.nodeName === 'LI') {

      const id = e.target.dataset.id
      window.sessionStorage.setItem('goodsId', id)
      window.location.href = 'detail.html'

  }
})
/************* 跳转详情页结束 ************/













